<?php

//就近 www.jiujin.me
global $_W, $_GPC;
$openid = m('user')->getOpenid();
$member = m('member')->getInfo($openid);

$total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_member') . " where uniacid=:uniacid and agentid=:agentid and status=0 and isagent=1 and zhaomu=1", array(':uniacid' => $_W['uniacid'], ':agentid'=>$member['id']));
if ($_W['isajax']) {
	if(isset($_GPC['type'])){
		//审核通过
		$ret['status'] = '审核通过';
		/*
		 *  gmm
		 *  修改：等级分配
		 *  时间：2015年11月25日
		 */
		if($member['agentlevel'] && $member['agentlevel'] == 1){		//我是战略合作伙伴
			$data = array('status' => 1, 'agenttime' => time(), 'agentlevel' => 2, 'zhaomu' => 2);
		}elseif($member['agentlevel'] && $member['agentlevel'] == 2){		//我是大伙伴
			$data = array('status' => 1, 'agenttime' => time(), 'agentlevel' => 3, 'zhaomu' => 2);
		}else{
			$data = array('status' => 1, 'agenttime' => time());
		}
		pdo_update('ewei_shop_member', $data, array('id' => $_GPC['id']));
		//gmm 2015-12-21 欢迎语
		$pushto = pdo_fetch('select openid from ' . tablename('ewei_shop_member') . " where uniacid=:uniacid and id=:id", array(':uniacid' => $_W['uniacid'], ':id'=>$_GPC['id']));
		if($pushto['openid']){
			if($data['agentlevel'] == 2){
				$this->model->sendMessage($pushto['openid'], array(), TM_COMMISSION_BECOME2);
			}else if($data['agentlevel'] == 3){
				$this->model->sendMessage($pushto['openid'], array(), TM_COMMISSION_BECOME3);
			}else{
				$this->model->sendMessage($pushto['openid'], array(), TM_COMMISSION_BECOME);
			}
		}
		
		show_json(1, $ret);
	}else{
		$pindex = max(1, intval($_GPC['page']));
		$psize = 20;
		$list = array();
		$list = pdo_fetchall("select * from " . tablename('ewei_shop_member') . " where agentid= ".$member['id']." and isagent=1 and status=0 and zhaomu=1 and uniacid = " . $_W['uniacid'] . "  ORDER BY createtime desc limit " . ($pindex - 1) * $psize . ',' . $psize);
		foreach ($list as &$row) {
			$info = $this->model->getInfo($row['openid'], array('total'));
			$row['createtime'] = date('Y-m-d H:i', $row['createtime']);
		}
		unset($row);
		show_json(1, array('list' => $list, 'pagesize' => $psize));
	}
}
include $this->template('confirm');